<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>个人健康档案系统-注册</title>
<link href="<%=basePath%>css/login.css" rel='stylesheet'
	type='text/css' />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="<%=basePath %>umeditor/third-party/jquery.min.js"></script>
<script type="text/javascript">
var isName=false;
var isNameLength=false;
var isPassword=false;
var isRePassword=false;
var isEmail=false;

function checkName(){
  var name=$("#name").val();
  if(name.length>2){
      isNameLength=true;
      $.ajax({  
        type : "post",  
        url : "<%=basePath %>checkUserName.do",  
        data : "name="+name,  
        dataType: "text",  
        success : function(msg) {  
        if(msg=="success"){
           isName=true;
           $("#message").html("");
          }else{
           isName=false;
           $("#message").html("该用户名已存在!");
              }  
           }  
       });
  }else{
      isNameLength=false;
     $("#message").html("用户名小于三位!");
  }

}

function checkPassword(){
   var password=$("#password").val();
   if(password.length > 5){
      isPassword=true;
   }else{
      isPassword=false;
      $("#message").html("密码小于6位!");
   }
}

function checkRePassword(){
  var rePassword=$("#rePassword").val();
  if(rePassword.length >5){
     isRePassword=true;
  }else{
     isRePassword=false;
      $("#message").html("密码小于6位!");
  }
}

function checkEmail(){
   var email=$("#email").val();
   var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
   if (filter.test(email)) {
		isEmail=true;
	} else {
		isEmail=false;
		 $("#message").html("邮箱格式不正确!");
	}
}

function checkSubmit(){
  if(isNameLength == false){
     $("#message").html("用户名小于三位!");
     return false;
  }
  
  if(isName == false){
     $("#message").html("该用户名已存在!");
     return false;
  }
  
  if(isPassword==false){
     $("#message").html("密码小于6位!");
     return false;
  }
  
  if(isRePassword==false){
    $("#message").html("密码小于6位!");
     return false;
  }
  
  if(isEmail==false){
     $("#message").html("邮箱格式不正确!");
     return false;
  }
  
  if($("#password").val()!=$("#rePassword").val()){
    $("#message").html("两次密码不一致!");
     return false;
  }
  
  return true;
}
</script>
<script type="application/x-javascript">
	 addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } 
</script>
</head>

<body>
	<div class="main">
		<div class="user">
			<img src="images/user.png" alt="">
		</div>
		<div class="login">
			<div class="inset">
				<!-----start-main---->
				<form action="<%=basePath%>saveRegister.do" method="post" onsubmit="return checkSubmit()">
					<div>
						<span style=" color: red;font-size: 14px;" id="message">${message}</span>
					</div>
					<div>
						<span><label>用户名</label><label style=" color: red;font-size: 15px;">大于3位!</label></span> <span><input type="text"
							class="textbox" name="name" id="name" onblur="checkName()"></span>
					</div>
					<div>
						<span><label>密码</label><label style=" color: red;font-size: 15px;">大于6位!</label></span><span><input type="password"
							class="password" name="password" id="password" onblur="checkPassword()"></span>
					</div>
					<div>
						<span><label>再次输入密码</label></span> <span><input
							type="password" class="password" name="rePassword" id="rePassword" onblur="checkRePassword()"></span>
					</div>
					<div>
						<span><label>邮箱</label></span> <span><input type="text"
							class="textbox" name="email" id="email" onblur="checkEmail()"></span>
					</div>
					<div>
						<span><label>性别  </label><input type="radio" name="sex" checked value="男"/>男    <input type="radio" name="sex" value="女"/>女</span>
					</div>
					<div class="sign">
						<div class="submit">
							<input type="submit" value="注册">
						</div>
						<span class="forget-pass"> <a href="<%=basePath%>login.do">已有账号直接登陆</a>
						</span>
						<div class="clear"></div>
					</div>
				</form>
			</div>
		</div>
		<!-----//end-main---->
	</div>
	<!-----start-copyright---->
	<div class="copy-right">
		<p>
			<a href="http://www.jyzhz.com/">惠州市金燕子科技有限公司</a>版权所有
		</p>
	</div>
	<!-----//end-copyright---->

</body>
</html>